import { profileUpload } from "@/api/upload";
/**选择图片 */
export const chooseImage = <T>(count = 1, num = -1): Promise<T> => {
  return new Promise((resolve, reject) => {
    uni.chooseImage({
      count: count,
      success: async (chooseImageRes) => {
        const tempFilePaths = chooseImageRes.tempFilePaths;
        if (count == 1) {
          const res: any = await profileUpload(tempFilePaths[0]);
          resolve(res.url);
        // } else {
        //   if (typeof tempFilePaths === "object") {
        //     let arr: string[] = [];
        //     let len = tempFilePaths.length-1;
        //     tempFilePaths.forEach(async (item, index) => {
        //       // 数量存在，数量加上上传数量小于最大数量
        //       if (num != -1 && index + num < count) {
        //         // const res: any = await profileUpload(item);
        //         // arr.push(res.url);
        //         console.log(len, index);
        //         arr.push(item)
        //         if (len == index) {
        //           resolve(arr as T);
        //         }
        //       }
        //     });
        //   }
        }
      },
      fail: (error) => {
        console.error("选择图片失败", error);
        reject(error);
      },
    });
  });
};
